package ynu.edu.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ynu.edu.common.controller.LogicController;
import ynu.edu.dao.IOrderDao;
import ynu.edu.entity.Order;
import ynu.edu.entity.User;
import ynu.edu.service.OrderService;
import ynu.edu.utils.Result;
import ynu.edu.utils.inna.AuthPermission;
import javax.annotation.Resource;
import javax.transaction.Transactional;

import static ynu.edu.controller.CustomerController.getResult;


@Api(tags = "订单的控制器")
@RestController
@RequestMapping("/order")
public class OrderController extends LogicController<OrderService, IOrderDao, Order,Long> {
    public OrderController(@Autowired OrderService ls) {
        super(ls);
    }
    @Resource
    private ModelMapper modelMapper;

    @AuthPermission(role = User.TYPE_CUSTOMER)
    @ApiOperation("获取某个订单")
    @GetMapping("/getOrderById/{orderId}")
    @Transactional
    public Result getOrderById(@PathVariable("orderId") Long orderId){
        Order order = getService().getOrderByOrderId(orderId);
        return getResult(modelMapper,order);
    }



}
